home *** CD-ROM | disk | FTP | other *** search
/ The World's Largest Collection of Windows Software / The World's Largest Collection of Windows Software - Disc 2.iso / textproc / _j1 / tex2rtf / src / tex2any.h < prev    next >
C/C++ Source or Header  |  1993-10-24  |  10KB  |  376 lines

  1. /*
  2.  * File:     tex2any.h
  3.  * Purpose:  Header file for LaTeX --> wxHelp conversion
  4.  *
  5.  *                       wxWindows 1.50
  6.  * Copyright (c) 1993 Artificial Intelligence Applications Institute,
  7.  *                   The University of Edinburgh
  8.  *
  9.  *                     Author: Julian Smart
  10.  *                        Date: 7-9-93
  11.  *
  12.  * Permission to use, copy, modify, and distribute this software and its
  13.  * documentation for any purpose is hereby granted without fee, provided
  14.  * that the above copyright notice, author statement and this permission
  15.  * notice appear in all copies of this software and related documentation.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS,
  18.  * IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
  19.  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  20.  *
  21.  * IN NO EVENT SHALL THE ARTIFICIAL INTELLIGENCE APPLICATIONS INSTITUTE OR THE
  22.  * UNIVERSITY OF EDINBURGH BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR
  23.  * CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM
  24.  * LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF
  25.  * DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
  26.  * THE USE OR PERFORMANCE OF THIS SOFTWARE.
  27.  */
  28.  
  29. #include <stdio.h>
  30. #include "wx.h"
  31. #include "wx_utils.h"
  32. #include "wx_list.h"
  33. #include "wxhlpblk.h"
  34.  
  35. /*
  36.  * We have a list of macro definitions which we must define
  37.  * in advance to enable the parsing to recognize macros.
  38.  */
  39.  
  40. class TexMacroDef: public wxObject
  41. {
  42.  public:
  43.   int no_args;
  44.   char *name;
  45.   Bool ignore;
  46.  
  47.   TexMacroDef(char *the_name, int n, Bool ig);
  48.   ~TexMacroDef(void);
  49. };
  50.  
  51. #define CHUNK_TYPE_MACRO    1
  52. #define CHUNK_TYPE_ARG      2
  53. #define CHUNK_TYPE_STRING   3
  54.  
  55. /*
  56.  We have nested lists to represent the Tex document.
  57.  Each element of a list of chunks can be one of:
  58.   - a plain string
  59.   - a macro with/without arguments. Arguments are lists of TexChunks.
  60.  
  61. Example (\toplevel is implicit but made explicit here):
  62.  
  63. AddMacroDef("mymat", 2);
  64.  
  65. \toplevel{The cat sat on the \mymat{very coarse and {\it cheap}}{mat}}.
  66.  
  67. Parsed as:
  68.  
  69. TexChunk: type = macro, name = toplevel, no_args = 1
  70.   Children:
  71.  
  72.     TexChunk: type = argument
  73.  
  74.       Children:
  75.         TexChunk: type = string, value = "The cat sat on the "
  76.         TexChunk: type = macro, name = mymat, no_args = 2
  77.  
  78.           Children:
  79.             TexChunk: type = argument
  80.  
  81.               Children:
  82.                 TexChunk: type = string, value = "very coarse and "
  83.                 TexChunk: type = macro, name = it, no_args = 1
  84.  
  85.                   Children:
  86.                     TexChunk: type = argument
  87.  
  88.                       Children:
  89.                         TexChunk: type = string, value = "cheap"
  90.  
  91.             TexChunk: type = argument
  92.  
  93.               Children:
  94.                 TexChunk: type = string, value = mat
  95.  */
  96.  
  97. class TexChunk: public wxObject
  98. {
  99.  public:
  100.   int type;
  101.   char *name;
  102.   char *value;
  103.   int no_args;
  104.   int argn;
  105.   Bool optional;      // Is an optional argument
  106.  
  107.   wxList children;
  108.   TexChunk(int the_type);
  109.   TexChunk(TexChunk& toCopy);
  110.   ~TexChunk(void);
  111. };
  112.  
  113. extern TexChunk     *TopLevel;
  114. extern wxList       MacroDefs;
  115. extern wxStringList IgnorableInputFiles; // Ignorable \input files, e.g. psbox.tex
  116.  
  117. Bool read_a_line(char *buf);
  118. Bool TexLoadFile(char *filename, char *customMacroDefs = NULL);
  119. int ParseArg(TexChunk *thisArg, wxList& children, char *buffer, int pos,
  120.            char *environment = NULL, Bool parseArgToBrace = TRUE, TexChunk *customMacroArgs = NULL);
  121. int ParseMacroBody(char *macro_name, TexChunk *parent, int no_args,
  122.            char *buffer, int pos, char *environment = NULL, Bool parseArgToBrace = TRUE, TexChunk *customMacroArgs = NULL);
  123. void TraverseDocument(void);
  124. void TraverseFromChunk(TexChunk *chunk, wxNode *thisNode = NULL, Bool childrenOnly = FALSE);
  125. #define TraverseChildrenFromChunk(arg) TraverseFromChunk(arg, NULL, TRUE)
  126. void SetCurrentOutput(FILE *fd);
  127. void SetCurrentOutputs(FILE *fd1, FILE *fd2);
  128. void AddMacroDef(char *name, int n, Bool ignore = FALSE);
  129. void TexInitialize(void);
  130. void TexCleanUp(void);
  131. void TexOutput(char *s, Bool ordinaryText = FALSE);
  132. char *GetArgData(void);             // Get the string for the current argument
  133. int GetNoArgs(void);                // Get the number of arguments for the current macro
  134. TexChunk *GetArgChunk(void);        // Get the chunk for the current argument
  135. TexChunk *GetTopLevelChunk(void);   // Get the chunk for the top level
  136. TexChunk *GetNextChunk(void);       // Look ahead to the next chunk
  137. Bool IsArgOptional(void);           // Is this argument an optional argument?
  138. void DefineDefaultMacros(void);     // Optional set of default macros
  139. int GetCurrentColumn(void);         // number of characters on current line
  140. extern wxPathList TexPathList;      // Path list, can be used for file searching.
  141.  
  142. // Major document styles
  143. #define LATEX_REPORT    1
  144. #define LATEX_ARTICLE   2
  145. #define LATEX_LETTER    3
  146. #define LATEX_BOOK      4
  147. #define LATEX_SLIDES    5
  148.  
  149. extern TexChunk *DocumentTitle;
  150. extern TexChunk *DocumentAuthor;
  151. extern TexChunk *DocumentDate;
  152. extern char *CurrentLabel;
  153. extern int DocumentStyle;
  154. extern int MinorDocumentStyle;
  155. extern char *BibliographyStyleString;
  156. extern char *DocumentStyleString;
  157.  
  158. extern int normalFont;
  159. extern int smallFont;
  160. extern int tinyFont;
  161. extern int largeFont1;
  162. extern int LargeFont2;
  163. extern int LARGEFont3;
  164. extern int hugeFont1;
  165. extern int HugeFont2;
  166. extern int HUGEFont3;
  167.  
  168. // Section font sizes
  169. extern int chapterFont;
  170. extern int sectionFont;
  171. extern int subsectionFont;
  172.  
  173. extern int chapterNo;
  174. extern int sectionNo;
  175. extern int subsectionNo;
  176. extern int subsubsectionNo;
  177. extern int figureNo;
  178.  
  179. extern int ParSkip;
  180. extern int ParIndent;
  181.  
  182. /*
  183.  * Local to Tex2Any library
  184.  *
  185.  */
  186.  
  187. extern char currentArgData[];
  188. extern Bool haveArgData; // If TRUE, we're simulating the data.
  189. void StartSimulateArgument(char *data);
  190. void EndSimulateArgument(void);
  191.  
  192. /*
  193.  * Client-defined
  194.  *
  195.  */
  196.  
  197. // Called on start/end of macro examination
  198. void OnMacro(char *name, int no_args, Bool start);
  199.  
  200. // Called on start/end of argument examination.
  201. // Return TRUE at the start of an argument to traverse
  202. // (output) the argument.
  203. Bool OnArgument(char *macro_name, int arg_no, Bool start);
  204.  
  205. // Default: library-defined
  206. void DefaultOnMacro(char *name, int no_args, Bool start);
  207.  
  208. // Default: library-defined
  209. Bool DefaultOnArgument(char *macro_name, int arg_no, Bool start);
  210.  
  211. // Called on error
  212. void OnError(char *msg);
  213.  
  214. // Called for information
  215. void OnInform(char *msg);
  216.  
  217. /*
  218.  * Useful utilities
  219.  *
  220.  */
  221.  
  222. // Look for \label macro, use this ref name if found or
  223. // make up a topic name otherwise.
  224. char *FindTopicName(TexChunk *chunk);
  225. void ResetTopicCounter(void);
  226.  
  227. // Parse unit eg. 14, 12pt, 34cm and return value in points.
  228. int ParseUnitArgument(char *unitArg);
  229.  
  230. // Set small, large, normal etc. point sizes for reference size
  231. void SetFontSizes(int pointSize);
  232.  
  233. /*
  234.  * Strip off any extension (dot something) from end of file,
  235.  * IF one exists. Inserts zero into buffer.
  236.  *
  237.  */
  238.  
  239. void StripExtension(char *buffer);
  240.  
  241. /*
  242.  * Reference structure
  243.  *
  244.  */
  245.  
  246. class TexRef: public wxObject
  247. {
  248.  public:
  249.   char *refLabel;      // Reference label
  250.   char *refFile;       // Reference filename (can be NULL)
  251.   char *sectionNumber; // Section or figure number (as a string)
  252.   TexRef(char *label, char *file, char *section)
  253.   {
  254.     refLabel = copystring(label);
  255.     refFile = file ? copystring(file) : NULL;
  256.     sectionNumber = section ? copystring(section) : copystring("??");
  257.   }
  258. };
  259.  
  260. extern wxList TexReferences;
  261.  
  262. /*
  263.  * Add a reference
  264.  *
  265.  */
  266.  
  267. void AddTexRef(char *name, char *file = NULL, char *sectionName = NULL,
  268.          int chapter = 0, int section = 0, int subsection = 0, int subsubsection = 0);
  269.  
  270. /*
  271.  * Read and write reference file (.ref), to resolve refs for second pass.
  272.  *
  273.  */
  274. void WriteTexReferences(char *filename);
  275. void ReadTexReferences(char *filename);
  276.  
  277. /*
  278.  * Bibliography stuff
  279.  *
  280.  */
  281.  
  282. class BibEntry: public wxObject
  283. {
  284.  public:
  285.   char *key;
  286.  
  287.   /*
  288.    * book, inbook, article, phdthesis, inproceedings, techreport
  289.    */
  290.   char *type;
  291.  
  292.   /*
  293.    * Possible fields
  294.    *
  295.    */
  296.   char *editor;
  297.   char *title;
  298.   char *booktitle;
  299.   char *author;
  300.   char *journal;
  301.   char *volume;
  302.   char *number;
  303.   char *year;
  304.   char *month;
  305.   char *pages;
  306.   char *chapter;
  307.   char *publisher;
  308.   char *address;
  309.   char *institution;
  310.   char *organization;
  311.   char *comment;
  312.  
  313.   inline BibEntry(void)
  314.   {
  315.     key = NULL;
  316.     type = NULL;
  317.     editor = NULL;
  318.     title = NULL;
  319.     booktitle = NULL;
  320.     author = NULL;
  321.     journal = NULL;
  322.     volume = NULL;
  323.     number = NULL;
  324.     chapter = NULL;
  325.     year = NULL;
  326.     month = NULL;
  327.     pages = NULL;
  328.     publisher = NULL;
  329.     address = NULL;
  330.     institution = NULL;
  331.     organization = NULL;
  332.     comment = NULL;
  333.   }
  334. };
  335.  
  336. extern wxList BibList;
  337. extern wxStringList CitationList;
  338.  
  339. Bool ReadBib(char *filename);
  340. void OutputBib(void);
  341. void ResolveBibReferences(void);
  342. void AddCitation(char *citeKey);
  343.  
  344. /*
  345.  * Ability to customize, or at least suppress unknown macro errors
  346.  *
  347.  */
  348.  
  349. extern wxList CustomMacroList;
  350.  
  351. #define CUSTOM_MACRO_IGNORE 0
  352. #define CUSTOM_MACRO_OUTPUT 1
  353. #define CUSTOM_MACRO_MARK   2
  354.  
  355. class CustomMacro: public wxObject
  356. {
  357.  public:
  358.   char *macroName;
  359.   char *macroBody;
  360.   int noArgs;
  361.   inline CustomMacro(char *name, int args, char *body)
  362.   {
  363.     noArgs = args;
  364.     macroName = copystring(name);
  365.     if (body)
  366.       macroBody = copystring(body);
  367.     else
  368.       macroBody = NULL;
  369.   }
  370. };
  371.  
  372. Bool ReadCustomMacros(char *filename);
  373. void ShowCustomMacros(void);
  374. CustomMacro *FindCustomMacro(char *name);
  375.  
  376.